<template>
  <a-spin :spinning="confirmLoading">
    <a-card :bordered="false" class="card">
      <a-row type="flex" style="margin-top: 10px">
        <a-col :span="24">
          <a-button v-if="!completeFlag" style="margin-left: 8px" @click="handleSubmit" type="primary">完成</a-button>
          <a-card :bordered="false" :body-style="{ padding: '0px' }">
            <chapter-list :completeFlag="completeFlag"
              ref="chapterRef"
              v-if="standardType == '综合指标' || standardType == '技术指标'"
              :slectedBusinessId="currentItemId"
              :projectId="scoreStandardInfo.projectId"
              :scoreStandardId="scoreStandardInfo.id"
              :standardType="standardType"
              :disabled="true"
                          :expertId="expertId"
                          :tenderId="tenderId"
            />
          </a-card>
        </a-col>
      </a-row>
    </a-card>
  </a-spin>
</template>

<script>
import FooterToolBar from '@/components/tools/FooterToolBar'
import '@/assets/less/TableExpand.less'
import ChapterList from './ChapterList'

import { httpAction, getAction } from '@/api/manage'

export default {
  name: 'score',
  components: { ChapterList, FooterToolBar },
  props: {
    entryId: {
      default: '',
    },
    standardType: {
      //指标类型（评分指标、价格指标
      default: '',
    },
    disabled: {
      default: false,
    },
    completeFlag:{

    },
    currentItemId:{},
    expertId:{},
    tenderId:{}
  },
  data() {
    return {
      // 选中的节点ID
      chapterId:null,
      disableSubmit: false,
      visible: false,
      varName: null,
      noticeContent: '',
      confirmLoading: false,
      scoreStandardId: '',
      scoreStandardInfo: { projectId: '', id: '' },
      model: {},
      scoreValue:'',
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      labelCol2: {
        xs: { span: 24 },
        sm: { span: 10 },
      },
      wrapperCol2: {
        xs: { span: 24 },
        sm: { span: 12 },
      },
      validateFlag:false
    }
  },
  watch: {
    entryId: {
      immediate: true,
      handler(val) {
        if (val != '' && val != undefined) {
          this.scoreStandardId = val
          this.loadScoreStandardInfo()
        }
      },
    },
  },
  created() {
    this.scoreStandardId = this.$route.query.scoreStandardId
    if (this.scoreStandardId) {
      this.loadScoreStandardInfo()
    } else {
    }
  },
  mounted() {
    //this.$refs.realForm.addBefore()
  },
  methods: {
    handleCancel() {
      this.close()
    },
    loadScoreStandardInfo() {
      var that = this
      getAction('exScoreStandard/exScoreStandard/queryById?id=' + that.scoreStandardId)
        .then((res) => {
          if (res.success) {
            that.scoreStandardInfo = res.result
          } else {
            that.$message.warning(res.message)
          }
        })
        .finally(() => {
          that.confirmLoading = false
        })
    },
    handleSubmit() {
      this.$emit('submit')
    },
    handleSave () {
      let list = this.$refs['chapterRef'].dataSource
      this.validateFlag = true
      this.validateScore(list)
      if (!this.validateFlag) {
        this.$message.error(`还有${this.standardType}指标未设置分值`)
        return false
      }
      if (this.validateFlag) {
        return true
      }
    },
    validateScore (list) {
      list.forEach(item => {
        if (!item.scoreValue) {
          this.validateFlag = false
        }
        if (item.children && item.children.length > 0) {
          this.validateScore(item.children)
        }
      })
    },
    exTenderFileInfoEdit() {
      this.$refs.refSetVariableList.show()
    },
  },
}
</script>

<style scoped>
</style>
